﻿using HrEFCore;
using HrIService;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HrService
{
	public class SGDService : ISGDService
	{
		private readonly MyDbContext myDbContext;

		public SGDService(MyDbContext myDbContext)
		{
			this.myDbContext = myDbContext;
		}

		public async Task<List<SGD>> HFSGDById(string HumanId)
		{
			return await myDbContext.SGD.Where(e => e.HumanId == HumanId).ToListAsync();
		}

		public List<SGD> SGDById(string SalaryGrantId)
		{
			return  myDbContext.SGD.Where(e => e.SalaryGrantId == SalaryGrantId).ToList();
		}

		public async Task<int> SGDFHUpdate(SGD sgd)
		{
			var sgd2 = myDbContext.SGD.Attach(sgd);
			sgd2.Property(e => e.BounsSum).IsModified = true;
			sgd2.Property(e => e.SaleSum).IsModified = true;
			sgd2.Property(e => e.DeductSum).IsModified = true;
			sgd2.Property(e => e.SalaryPaidSum).IsModified = true;
			return await myDbContext.SaveChangesAsync();
		}

		public async Task<int> SGDInsert(List<SGD> sgd)
		{
			await myDbContext.SGD.AddRangeAsync(sgd);
			return await myDbContext.SaveChangesAsync();
		}
	}
}